﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using eTerm.MsSql.DbProvider;

namespace eTerm.Platform.Web.Order
{
    public partial class SubmitRequire : BasePage
    {
        protected override string PageCode
        {
            get
            {
                return @"SUBORDERREQUIRE";
            }
        }

        protected override void InitPageLoad()
        {
            btnSave.CausesValidation = !string.IsNullOrEmpty(DetailMode1.EntityIdentity);
        }

        protected override void InitEasyUI()
        {
            BaseRegisterStartupScript<UpdatePanel>(GetUpdatePanel(@"pnlContent") as UpdatePanel, btnMasterDetail.ClientID, string.Format(@"$('#{0}').linkbutton({{   
    iconCls: 'icon-search'  
}});  
", btnMasterDetail.ClientID), true);

            BaseRegisterStartupScript<UpdatePanel>(GetUpdatePanel(@"pnlContent") as UpdatePanel, btnPnr.ClientID, string.Format(@"$('#{0}').linkbutton({{   
    iconCls: 'icon-search'  
}});  
", btnPnr.ClientID), true);

            BaseRegisterStartupScript<UpdatePanel>(GetUpdatePanel(@"pnlContent") as UpdatePanel, btnSave.ClientID, string.Format(@"$('#{0}').linkbutton({{   
    iconCls: 'icon-save'  
}});  
", btnSave.ClientID), true);


        }

        

        protected void btnPnr_Click(object sender, EventArgs e)
        {
            PNRMode1.Visible = true;
            DetailMode1.Visible = false;
            btnSave.Visible = true;
        }

        protected void btnMasterDetail_Click(object sender, EventArgs e)
        {
            PNRMode1.Visible =false;
            DetailMode1.Visible = true;
            btnSave.Visible = true;
            DetailMode1.InitControl();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (PNRMode1.Visible)
            {
                PnrRequire model = (PNRMode1 as BaseEntityUserControl<PnrRequire>).Save();
                DetailMode1.Visible = true;
                PNRMode1.Visible = false;
                (DetailMode1 as BaseEntityUserControl<PnrRequire>).EntityIdentity = model.Id.ToString();
                (DetailMode1 as BaseEntityUserControl<PnrRequire>).IsReadOnly = true;
                (DetailMode1 as BaseEntityUserControl<PnrRequire>).InitControl();
            }
            else
            {
                PnrRequire model  =(DetailMode1 as BaseEntityUserControl<PnrRequire>).Save();
                if (string.IsNullOrEmpty(DetailMode1.EntityIdentity)) {
                    DetailMode1.EntityIdentity = model.Id.ToString();
                    DetailMode1.IsReadOnly = false;
                    DetailMode1.InitControl();
                }
            }
            btnSave.Visible = false;
        }
    }
}
